home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_lrm / chap05.doc < prev    next >
Text File  |  1996-01-30  |  28KB  |  748 lines

  1.                                5. Statements
  2.  
  3.  
  4. A  statement  defines  an  action  to be performed;  the process by which a
  5. statement achieves its action is called execution of the statement.
  6.  
  7.  
  8. This chapter describes the general  rules  applicable  to  all  statements.
  9. Some  specific  statements are discussed in later chapters.  Procedure call
  10. statements are described in Chapter 6 on subprograms.  Entry  call,  delay,
  11. accept,  select,  and abort statements are described in Chapter 9 on tasks.
  12. Raise statements are described  in  Chapter  11  on  exceptions,  and  code
  13. statements  in Chapter 13.  The remaining forms of statements are presented
  14. in this chapter.
  15.  
  16.  
  17. References:  abort statement 9.10, accept  statement  9.5,  code  statement
  18. 13.8,  delay  statement  9.6,  entry  call  statement  9.5,  procedure call
  19. statement 6.4, raise statement 11.3, select statement 9.7
  20.  
  21. 5.1  Simple and Compound Statements - Sequences of Statements
  22.  
  23.  
  24. A statement is either simple or compound.  A simple statement  encloses  no
  25. other  statement.   A  compound statement can enclose simple statements and
  26. other compound statements.
  27.  
  28.  
  29.     sequence_of_statements ::= statement {statement}
  30.  
  31.     statement ::=
  32.        {label} simple_statement | {label} compound_statement
  33.  
  34.     simple_statement ::= null_statement
  35.        | assignment_statement | procedure_call_statement
  36.        | exit_statement       | return_statement
  37.        | goto_statement       | entry_call_statement
  38.        | delay_statement      | abort_statement
  39.        | raise_statement      | code_statement
  40.  
  41.     compound_statement ::=
  42.          if_statement         | case_statement
  43.        | loop_statement       | block_statement
  44.        | accept_statement     | select_statement
  45.  
  46.     label ::= <<label_simple_name>>
  47.  
  48.     null_statement ::= null;
  49.  
  50.  
  51. A statement is said to be labeled by the label name of  any  label  of  the
  52. statement.  A label name, and similarly a loop or block name, is implicitly
  53. declared  at  the  end  of  the  declarative  part  of  the innermost block
  54. statement, subprogram body, package body, task body, or generic  body  that
  55. encloses  the  labeled  statement,  the  named loop statement, or the named
  56. block statement, as the case may be.   For  a  block  statement  without  a
  57. declarative  part,  an implicit declarative part (and preceding declare) is
  58. assumed.
  59.  
  60.  
  61. The implicit declarations for different label names, loop names, and  block
  62. names  occur  in  the  same  order  as  the beginnings of the corresponding
  63. labeled  statements,  loop  statements,  and  block  statements.   Distinct
  64. identifiers  must  be  used  for  all label, loop, and block names that are
  65. implicitly declared within the body of a  program  unit,  including  within
  66. block statements enclosed by this body, but excluding within other enclosed
  67. program  units  (a  program  unit is either a subprogram, a package, a task
  68. unit, or a generic unit).
  69.  
  70.  
  71. Execution of a null statement has no other effect than to pass to the  next
  72. action.
  73.  
  74.  
  75. The  execution of a sequence of statements consists of the execution of the
  76. individual statements in succession until the sequence is completed,  or  a
  77. transfer of control takes place.  A transfer of control is caused either by
  78. the execution of an exit, return, or goto statement;  by the selection of a
  79. terminate  alternative; by the raising of an exception;  or (indirectly) by
  80. the execution of an abort statement.
  81.  
  82.  
  83. Examples of labeled statements:
  84.  
  85.     <<HERE>> <<ICI>> <<AQUI>> <<HIER>> null;
  86.  
  87.     <<AFTER>> X := 1;
  88.  
  89. Note:
  90.  
  91.  
  92. The scope of a declaration starts at the place of  the  declaration  itself
  93. (see  8.2).   In  the case of a label, loop, or block name, it follows from
  94. this rule that the scope of the  implicit  declaration  starts  before  the
  95. first  explicit occurrence of the corresponding name, since this occurrence
  96. is either in a statement label, a loop statement, a block statement,  or  a
  97. goto  statement.   An  implicit declaration in a block statement may hide a
  98. declaration given in an outer program unit or block statement (according to
  99. the usual rules of hiding explained in section 8.3).
  100.  
  101.  
  102. References:   abort  statement  9.10,  accept  statement  9.5,   assignment
  103. statement  5.2,  block  name  5.6, block statement 5.6, case statement 5.4,
  104. code statement 13.8, declaration 3.1, declarative part 3.9, delay statement
  105. 9.6, entry call statement 9.5, exception 11, exit  statement  5.7,  generic
  106. body 12.1, generic unit 12, goto statement 5.9, hiding 8.3, identifier 2.3,
  107. if  statement  5.3, implicit declaration 3.1, loop name 5.5, loop statement
  108. 5.5, package 7, package body 7.1, procedure  call  statement  6.4,  program
  109. unit  6,  raise  statement 11.3, raising of exceptions 11, return statement
  110. 5.8, scope 8.2, select  statement  9.7,  simple  name  4.1,  subprogram  6,
  111. subprogram  body  6.3,  task  9,  task  body  9.1, task unit 9.1, terminate
  112. alternative 9.7.1, terminated task 9.4
  113.  
  114. 5.2  Assignment Statement
  115.  
  116.  
  117. An assignment statement replaces the current value of a variable with a new
  118. value specified by an expression.  The named variable  and  the  right-hand
  119. side  expression must be of the same type;  this type must not be a limited
  120. type.
  121.  
  122.  
  123.     assignment_statement ::=
  124.        variable_name := expression;
  125.  
  126.  
  127. For the execution of an assignment statement, the  variable  name  and  the
  128. expression  are  first  evaluated, in some order that is not defined by the
  129. language.  A check is then made that the value of the expression belongs to
  130. the subtype of the variable, except in the case of a variable  that  is  an
  131. array  (the  assignment  then involves a subtype conversion as described in
  132. section 5.2.1).  Finally, the value of the expression becomes the new value
  133. of the variable.
  134.  
  135.  
  136. The exception CONSTRAINT_ERROR is raised  if  the  above-mentioned  subtype
  137. check  fails;   in  such  a  case the current value of the variable is left
  138. unchanged.  If the variable is a subcomponent that depends on discriminants
  139. of an unconstrained record variable, then the execution of  the  assignment
  140. is  erroneous if the value of any of these discriminants is changed by this
  141. execution.
  142.  
  143.  
  144. Examples:
  145.  
  146.     VALUE := MAX_VALUE - 1;
  147.     SHADE := BLUE;
  148.  
  149.     NEXT_FRAME(F)(M, N) := 2.5;        --  see 4.1.1
  150.     U := DOT_PRODUCT(V, W);            --  see 6.5
  151.  
  152.     WRITER := (STATUS => OPEN, UNIT => PRINTER, LINE_COUNT => 60);  -- see 3.7.3
  153.     NEXT_CAR.all := (72074, null);    --  see 3.8.1
  154.  
  155.  
  156. Examples of constraint checks:
  157.  
  158.     I, J : INTEGER range 1 .. 10;
  159.     K    : INTEGER range 1 .. 20;
  160.      ...
  161.  
  162.     I := J;  --  identical ranges
  163.     K := J;  --  compatible ranges
  164.     J := K;  --  will raise the exception CONSTRAINT_ERROR if K > 10
  165.  
  166. Notes:
  167.  
  168.  
  169. The values of the discriminants of an object designated by an access  value
  170. cannot  be  changed  (not  even by assigning a complete value to the object
  171. itself) since such objects, created by allocators, are  always  constrained
  172. (see 4.8);  however, subcomponents of such objects may be unconstrained.
  173.  
  174.  
  175. If  the  right-hand  side  expression  is either a numeric literal or named
  176. number, or an attribute that yields a result of type  universal_integer  or
  177. universal_real, then an implicit type conversion is performed, as described
  178. in section 4.6.
  179.  
  180.  
  181. The  determination  of  the type of the variable of an assignment statement
  182. may require consideration of the expression if the  variable  name  can  be
  183. interpreted  as  the  name  of  a  variable  designated by the access value
  184. returned by a function call, and similarly, as a component or slice of such
  185. a variable (see section 8.7 for the context of overload resolution).
  186.  
  187.  
  188. References:  access type 3.8, allocator 4.8, array  3.6,  array  assignment
  189. 5.2.1,  component  3.6 3.7, constraint_error exception 11.1, designate 3.8,
  190. discriminant 3.7.1, erroneous 1.6, evaluation 4.5, expression 4.4, function
  191. call 6.4, implicit type conversion 4.6,  name  4.1,  numeric  literal  2.4,
  192. object  3.2,  overloading  6.6  8.7, slice 4.1.2, subcomponent 3.3, subtype
  193. 3.3, subtype  conversion  4.6,  type  3.3,  universal_integer  type  3.5.4,
  194. universal_real type 3.5.6, variable 3.2.1
  195.  
  196. 5.2.1  Array Assignments
  197.  
  198.  
  199. If  the variable of an assignment statement is an array variable (including
  200. a slice variable), the value of the expression is implicitly  converted  to
  201. the  subtype  of the array variable;  the result of this subtype conversion
  202. becomes the new value of the array variable.
  203.  
  204.  
  205. This means that the new value of each component of the  array  variable  is
  206. specified  by  the  matching  component  in  the  array  value  obtained by
  207. evaluation of the expression (see 4.5.2  for  the  definition  of  matching
  208. components).   The subtype conversion checks that for each component of the
  209. array variable there is a matching component in the array value,  and  vice
  210. versa.   The  exception CONSTRAINT_ERROR is raised if this check fails;  in
  211. such a case the value of each component  of  the  array  variable  is  left
  212. unchanged.
  213.  
  214.  
  215. Examples:
  216.  
  217.     A : STRING(1 .. 31);
  218.     B : STRING(3 .. 33);
  219.      ...
  220.  
  221.     A := B;  --  same number of components
  222.  
  223.     A(1 .. 9)  := "tar sauce";
  224.     A(4 .. 12) := A(1 .. 9);  --  A(1 .. 12) = "tartar sauce"
  225.  
  226. Notes:
  227.  
  228.  
  229. Array assignment is defined even in the case of overlapping slices, because
  230. the  expression  on  the right-hand side is evaluated before performing any
  231. component assignment.  In the above example, an implementation yielding A(1
  232. .. 12) = "tartartartar" would be incorrect.
  233.  
  234.  
  235. The implicit subtype conversion described above for assignment to an  array
  236. variable  is performed only for the value of the right-hand side expression
  237. as a whole;  it is not performed for subcomponents that are  array  values.
  238.  
  239.  
  240. References:   array  3.6,  assignment 5.2, constraint_error exception 11.1,
  241. matching array components 4.5.2, slice 4.1.2, subtype conversion 4.6,  type
  242. 3.3, variable 3.2.1
  243.  
  244. 5.3  If Statements
  245.  
  246.  
  247. An if statement selects for execution one or none of the enclosed sequences
  248. of  statements, depending on the (truth) value of one or more corresponding
  249. conditions.
  250.  
  251.  
  252.     if_statement ::=
  253.         if condition then
  254.           sequence_of_statements
  255.        {elsif condition then
  256.           sequence_of_statements}
  257.        [else
  258.           sequence_of_statements]
  259.         end if;
  260.  
  261.     condition ::= boolean_expression
  262.  
  263.  
  264. An expression specifying a condition must be of a boolean type.
  265.  
  266.  
  267. For the execution of an if statement, the condition specified after if, and
  268. any conditions specified after elsif, are evaluated in succession (treating
  269. a final else as elsif TRUE then),  until  one  evaluates  to  TRUE  or  all
  270. conditions  are  evaluated  and yield FALSE.  If one condition evaluates to
  271. TRUE, then the corresponding sequence of statements is executed;  otherwise
  272. none of the sequences of statements is executed.
  273.  
  274.  
  275. Examples:
  276.  
  277.     if MONTH = DECEMBER and DAY = 31 then
  278.        MONTH := JANUARY;
  279.        DAY   := 1;
  280.        YEAR  := YEAR + 1;
  281.     end if;
  282.  
  283.     if LINE_TOO_SHORT then
  284.        raise LAYOUT_ERROR;
  285.     elsif LINE_FULL then
  286.        NEW_LINE;
  287.        PUT(ITEM);
  288.     else
  289.        PUT(ITEM);
  290.     end if;
  291.  
  292.     if MY_CAR.OWNER.VEHICLE /= MY_CAR then            --  see 3.8
  293.        REPORT ("Incorrect data");
  294.     end if;
  295.  
  296.  
  297. References:  boolean type 3.5.3, evaluation 4.5, expression  4.4,  sequence
  298. of statements 5.1
  299.  
  300. 5.4  Case Statements
  301.  
  302.  
  303. A  case  statement  selects  for  execution  one of a number of alternative
  304. sequences of statements;  the chosen alternative is defined by the value of
  305. an expression.
  306.  
  307.  
  308.     case_statement ::=
  309.        case expression is
  310.            case_statement_alternative
  311.           {case_statement_alternative}
  312.        end case;
  313.  
  314.     case_statement_alternative ::=
  315.        when choice {| choice } =>
  316.           sequence_of_statements
  317.  
  318.  
  319. The expression must be of  a  discrete  type  which  must  be  determinable
  320. independently  of the context in which the expression occurs, but using the
  321. fact that the expression must be of a discrete type.  Moreover, the type of
  322. this expression must not be a generic formal type.  Each choice in  a  case
  323. statement alternative must be of the same type as the expression;  the list
  324. of  choices specifies for which values of the expression the alternative is
  325. chosen.
  326.  
  327.  
  328. If the expression is the name of an object whose subtype  is  static,  then
  329. each  value  of  this subtype must be represented once and only once in the
  330. set of choices of the case statement, and no other value is allowed;   this
  331. rule  is  likewise  applied  if the expression is a qualified expression or
  332. type conversion whose type mark denotes a static subtype.   Otherwise,  for
  333. other  forms of expression, each value of the (base) type of the expression
  334. must be represented once and only once in the set of choices, and no  other
  335. value is allowed.
  336.  
  337.  
  338. The  simple  expressions  and  discrete  ranges  given as choices in a case
  339. statement must be static.  A choice defined by a discrete range stands  for
  340. all  values  in the corresponding range (none if a null range).  The choice
  341. others is only allowed for the last alternative and as its only choice;  it
  342. stands for all values (possibly none) not given in the choices of  previous
  343. alternatives.  A component simple name is not allowed as a choice of a case
  344. statement alternative.
  345.  
  346.  
  347. The  execution  of  a  case  statement  consists  of  the evaluation of the
  348. expression followed by the execution of the chosen sequence of  statements.
  349.  
  350.  
  351. Examples:
  352.  
  353.     case SENSOR is
  354.        when ELEVATION  => RECORD_ELEVATION(SENSOR_VALUE);
  355.        when AZIMUTH    => RECORD_AZIMUTH  (SENSOR_VALUE);
  356.        when DISTANCE   => RECORD_DISTANCE (SENSOR_VALUE);
  357.        when others     => null;
  358.     end case;
  359.  
  360.     case TODAY is
  361.        when MON        => COMPUTE_INITIAL_BALANCE;
  362.        when FRI        => COMPUTE_CLOSING_BALANCE;
  363.        when TUE .. THU => GENERATE_REPORT(TODAY);
  364.        when SAT .. SUN => null;
  365.     end case;
  366.  
  367.     case BIN_NUMBER(COUNT) is
  368.        when 1      => UPDATE_BIN(1);
  369.        when 2      => UPDATE_BIN(2);
  370.        when 3 | 4  =>
  371.           EMPTY_BIN(1);
  372.           EMPTY_BIN(2);
  373.        when others => raise ERROR;
  374.     end case;
  375.  
  376. Notes:
  377.  
  378.  
  379. The  execution  of  a  case statement chooses one and only one alternative,
  380. since the choices are exhaustive and mutually exclusive.  Qualification  of
  381. the expression of a case statement by a static subtype can often be used to
  382. limit the number of choices that need be given explicitly.
  383.  
  384.  
  385. An  others  choice  is  required  in  a  case statement if the  type of the
  386. expression is the type universal_integer (for example, if the expression is
  387. an integer literal), since this is the only way to cover all values of  the
  388. type universal_integer.
  389.  
  390.  
  391. References:   base  type  3.3, choice 3.7.3, context of overload resolution
  392. 8.7, discrete type 3.5, expression 4.4, function call 6.4,  generic  formal
  393. type  12.1,  conversion  4.6, discrete type 3.5, enumeration literal 3.5.1,
  394. expression 4.4, name 4.1, object  3.2.1,  overloading  6.6  8.7,  qualified
  395. expression  4.7,  sequence  of  statements  5.1, static discrete range 4.9,
  396. static subtype 4.9, subtype 3.3, type 3.3, type conversion 4.6,  type  mark
  397. 3.3.2
  398.  
  399. 5.5  Loop Statements
  400.  
  401.  
  402. A  loop  statement includes a sequence of statements that is to be executed
  403. repeatedly, zero or more times.
  404.  
  405.  
  406.     loop_statement ::=
  407.        [loop_simple_name:]
  408.           [iteration_scheme] loop
  409.              sequence_of_statements
  410.            end loop [loop_simple_name];
  411.  
  412.     iteration_scheme ::= while condition
  413.        | for loop_parameter_specification
  414.  
  415.     loop_parameter_specification ::=
  416.        identifier in [reverse] discrete_range
  417.  
  418.  
  419. If a loop statement has a loop simple name, this simple name must be  given
  420. both at the beginning and at the end.
  421.  
  422.  
  423. A  loop  statement without an iteration scheme specifies repeated execution
  424. of the sequence of statements.  Execution of the loop statement is complete
  425. when the loop is left  as  a  consequence  of  the  execution  of  an  exit
  426. statement, or as a consequence of some other transfer of control (see 5.1).
  427.  
  428.  
  429. For  a  loop  statement  with  a  while  iteration scheme, the condition is
  430. evaluated before each execution of the  sequence  of  statements;   if  the
  431. value  of the condition is TRUE, the sequence of statements is executed, if
  432. FALSE the execution of the loop statement is complete.
  433.  
  434.  
  435. For a loop statement with  a  for  iteration  scheme,  the  loop  parameter
  436. specification  is  the  declaration  of  the  loop parameter with the given
  437. identifier.  The loop parameter is an object whose type is the base type of
  438. the discrete range (see 3.6.1).  Within the  sequence  of  statements,  the
  439. loop parameter is a constant.  Hence a loop parameter is not allowed as the
  440. (left-hand  side)  variable of an assignment statement.  Similarly the loop
  441. parameter must not be given as an out or in out parameter of a procedure or
  442. entry call statement, or as an in out parameter of a generic instantiation.
  443.  
  444.  
  445. For the execution of a loop statement with a for iteration scheme, the loop
  446. parameter specification is first elaborated.  This elaboration creates  the
  447. loop parameter and evaluates the discrete range.
  448.  
  449.  
  450. If  the discrete range is a null range, the execution of the loop statement
  451. is complete.  Otherwise, the sequence of statements is  executed  once  for
  452. each  value  of the discrete range (subject to the loop not being left as a
  453. consequence of the execution of an exit statement or as  a  consequence  of
  454. some  other  transfer  of  control).   Prior  to  each  such iteration, the
  455. corresponding  value  of  the  discrete  range  is  assigned  to  the  loop
  456. parameter.   These  values  are  assigned  in  increasing  order unless the
  457. reserved word reverse is present, in which case the values are assigned  in
  458. decreasing order.
  459.  
  460.  
  461. Example of a loop statement without an iteration scheme:
  462.  
  463.     loop
  464.        GET(CURRENT_CHARACTER);
  465.        exit when CURRENT_CHARACTER = '*';
  466.     end loop;
  467.  
  468.  
  469. Example of a loop statement with a while iteration scheme:
  470.  
  471.     while BID(N).PRICE < CUT_OFF.PRICE loop
  472.        RECORD_BID(BID(N).PRICE);
  473.        N := N + 1;
  474.     end loop;
  475.  
  476.  
  477. Example of a loop statement with a for iteration scheme:
  478.  
  479.     for J in BUFFER'RANGE loop     --  legal even with a null range
  480.        if BUFFER(J) /= SPACE then
  481.           PUT(BUFFER(J));
  482.        end if;
  483.     end loop;
  484.  
  485.  
  486. Example of a loop statement with a loop simple name:
  487.  
  488.     SUMMATION:
  489.        while NEXT /= HEAD loop       -- see 3.8
  490.           SUM  := SUM + NEXT.VALUE;
  491.           NEXT := NEXT.SUCC;
  492.        end loop SUMMATION;
  493.  
  494. Notes:
  495.  
  496.  
  497. The scope of a loop parameter extends from the loop parameter specification
  498. to  the end of the loop statement, and the visibility rules are such that a
  499. loop parameter is only visible within the sequence  of  statements  of  the
  500. loop.
  501.  
  502.  
  503. The  discrete  range  of  a  for  loop  is evaluated just once.  Use of the
  504. reserved word reverse does not  alter  the  discrete  range,  so  that  the
  505. following  iteration  schemes  are  not  equivalent;   the first has a null
  506. range.
  507.  
  508.     for J in reverse 1 .. 0
  509.     for J in 0 .. 1
  510.  
  511.  
  512. Loop names are also used in exit statements, and in expanded  names  (in  a
  513. prefix of the loop parameter).
  514.  
  515.  
  516. References:   actual  parameter  6.4.1, assignment statement 5.2, base type
  517. 3.3, bound of a range  3.5,  condition  5.3,  constant  3.2.1,  context  of
  518. overload  resolution  8.7,  conversion 4.6, declaration 3.1, discrete range
  519. 3.6.1, elaboration 3.1, entry call  statement  9.5,  evaluation  4.5,  exit
  520. statement  5.7,  expanded  name  4.1.3,  false boolean value 3.5.3, generic
  521. actual parameter 12.3, generic  instantiation  12.3,  goto  statement  5.9,
  522. identifier  2.3,  integer  type 3.5.4, null range 3.5, object 3.2.1, prefix
  523. 4.1, procedure call 6.4, raising  of  exceptions  11,  reserved  word  2.9,
  524. return  statement  5.8,  scope 8.2, sequence of statements 5.1, simple name
  525. 4.1,  terminate  alternative  9.7.1,  true  boolean  value   3.5.3   3.5.4,
  526. visibility 8.3
  527.  
  528. 5.6  Block Statements
  529.  
  530.  
  531. A  block statement encloses a sequence of statements optionally preceded by
  532. a declarative part and optionally followed by exception handlers.
  533.  
  534.  
  535.     block_statement ::=
  536.        [block_simple_name:]
  537.           [declare
  538.                declarative_part]
  539.            begin
  540.                sequence_of_statements
  541.           [exception
  542.                exception_handler
  543.               {exception_handler}]
  544.            end [block_simple_name];
  545.  
  546.  
  547. If a block statement has a block simple name,  this  simple  name  must  be
  548. given both at the beginning and at the end.
  549.  
  550.  
  551. The  execution  of  a  block  statement  consists of the elaboration of its
  552. declarative part (if any) followed by the  execution  of  the  sequence  of
  553. statements.   If  the block statement has exception handlers, these service
  554. corresponding exceptions that  are  raised  during  the  execution  of  the
  555. sequence of statements (see 11.2).
  556.  
  557.  
  558. Example:
  559.  
  560.     SWAP:
  561.        declare
  562.           TEMP : INTEGER;
  563.        begin
  564.           TEMP := V; V := U; U := TEMP;
  565.        end SWAP;
  566.  
  567. Notes:
  568.  
  569.  
  570. If  task  objects  are declared within a block statement whose execution is
  571. completed, the block statement is not left until all  its  dependent  tasks
  572. are terminated (see 9.4).  This rule applies also to a completion caused by
  573. an exit, return, or goto statement;  or by the raising of an exception.
  574.  
  575.  
  576. Within  a  block  statement,  the  block name can be used in expanded names
  577. denoting local entities such as SWAP.TEMP in the above example  (see  4.1.3
  578. (f)).
  579.  
  580.  
  581. References:   declarative  part  3.9, dependent task 9.4, exception handler
  582. 11.2, exit statement 5.7, expanded name 4.1.3, goto statement 5.9,  raising
  583. of  exceptions 11, return statement 5.8, sequence of statements 5.1, simple
  584. name 4.1, task object 9.2
  585.  
  586. 5.7  Exit Statements
  587.  
  588.  
  589. An exit statement is used to complete the execution of  an  enclosing  loop
  590. statement (called the loop in what follows);  the completion is conditional
  591. if the exit statement includes a condition.
  592.  
  593.  
  594.     exit_statement ::=
  595.        exit [loop_name] [when condition];
  596.  
  597.  
  598. An  exit  statement with a loop name is only allowed within the named loop,
  599. and applies to that loop;  an exit statement without a loop  name  is  only
  600. allowed within a loop, and applies to the innermost enclosing loop (whether
  601. named or not).  Furthermore, an exit statement that applies to a given loop
  602. must  not appear within a subprogram body, package body, task body, generic
  603. body, or accept statement, if this construct  is  itself  enclosed  by  the
  604. given loop.
  605.  
  606.  
  607. For the execution of an exit statement, the condition, if present, is first
  608. evaluated.   Exit from the loop then takes place if the value is TRUE or if
  609. there is no condition.
  610.  
  611.  
  612. Examples:
  613.  
  614.     for N in 1 .. MAX_NUM_ITEMS loop
  615.        GET_NEW_ITEM(NEW_ITEM);
  616.        MERGE_ITEM(NEW_ITEM, STORAGE_FILE);
  617.        exit when NEW_ITEM = TERMINAL_ITEM;
  618.     end loop;
  619.  
  620.     MAIN_CYCLE:
  621.        loop
  622.           --  initial statements
  623.           exit MAIN_CYCLE when FOUND;
  624.           --  final statements
  625.        end loop MAIN_CYCLE;
  626.  
  627. Note:
  628.  
  629.  
  630. Several nested loops can be exited by an  exit  statement  that  names  the
  631. outer loop.
  632.  
  633.  
  634. References:   accept  statement 9.5, condition 5.3, evaluation 4.5, generic
  635. body 12.1, loop name 5.5, loop statement 5.5, package body 7.1,  subprogram
  636. body 6.3, true boolean value 3.5.3
  637.  
  638. 5.8  Return Statements
  639.  
  640.  
  641. A  return  statement  is  used  to  complete the execution of the innermost
  642. enclosing function, procedure, or accept statement.
  643.  
  644.  
  645.     return_statement ::= return [expression];
  646.  
  647.  
  648. A return statement is only allowed within  the  body  of  a  subprogram  or
  649. generic  subprogram,  or  within  an  accept  statement, and applies to the
  650. innermost (enclosing) such construct;  a return statement  is  not  allowed
  651. within  the  body  of a task unit,  package, or generic package enclosed by
  652. this construct (on  the  other  hand,  it  is  allowed  within  a  compound
  653. statement  enclosed  by  this  construct  and,  in  particular,  in a block
  654. statement).
  655.  
  656.  
  657. A return statement for an accept statement or for the body of  a  procedure
  658. or  generic  procedure  must not include an expression.  A return statement
  659. for the body of a function or generic function must include an  expression.
  660.  
  661.  
  662. The  value  of  the expression defines the result returned by the function.
  663. The type of this expression must be the base type of the  type  mark  given
  664. after  the  reserved  word  return  in the specification of the function or
  665. generic function (this type mark defines the result subtype).
  666.  
  667.  
  668. For the execution of a return statement, the expression (if any)  is  first
  669. evaluated and a check is made that the value belongs to the result subtype.
  670. The  execution  of  the  return statement is thereby completed if the check
  671. succeeds;  so also is the execution of the  subprogram  or  of  the  accept
  672. statement.   The  exception  CONSTRAINT_ERROR is raised at the place of the
  673. return statement if the check fails.
  674.  
  675.  
  676. Examples:
  677.  
  678.     return;                         -- in a procedure
  679.     return KEY_VALUE(LAST_INDEX);   -- in a function
  680.  
  681. Note:
  682.  
  683.  
  684. If the expression is either a  numeric  literal  or  named  number,  or  an
  685. attribute that yields a result of type universal_integer or universal_real,
  686. then  an  implicit  conversion  of  the result is performed as described in
  687. section 4.6.
  688.  
  689.  
  690. References:  accept  statement  9.5,  attribute  A,  block  statement  5.6,
  691. constraint_error   exception  11.1,  expression  4.4,  function  body  6.3,
  692. function call 6.4, generic body 12.1, implicit type conversion  4.6,  named
  693. number  3.2,  numeric  literal  2.4,  package body 7.1, procedure body 6.3,
  694. reserved word 2.9, result subtype  6.1,  subprogram  body  6.3,  subprogram
  695. specification   6.1,   subtype   3.3,  task  body  9.1,  type  mark  3.3.2,
  696. universal_integer type 3.5.4, universal_real type 3.5.6
  697.  
  698. 5.9  Goto Statements
  699.  
  700.  
  701. A goto statement specifies  an  explicit  transfer  of  control  from  this
  702. statement to a target statement named by a label.
  703.  
  704.  
  705.     goto_statement ::= goto label_name;
  706.  
  707.  
  708. The  innermost  sequence  of  statements that encloses the target statement
  709. must also enclose the goto statement (note that the goto statement can be a
  710. statement of an inner sequence).   Furthermore,  if  a  goto  statement  is
  711. enclosed  by  an  accept  statement or the body of a program unit, then the
  712. target statement must not be outside this enclosing construct;  conversely,
  713. it follows from the previous rule that if the target statement is  enclosed
  714. by such a construct, then the goto statement cannot be outside.
  715.  
  716.  
  717. The  execution  of  a  goto statement transfers control to the named target
  718. statement.
  719.  
  720. Note:
  721.  
  722.  
  723. The above rules allow transfer of control to a statement  of  an  enclosing
  724. sequence  of  statements  but  not  the  reverse.  Similarly, they prohibit
  725. transfers of control such as between alternatives of a case  statement,  if
  726. statement,  or  select  statement;  between exception handlers;  or from an
  727. exception handler of a frame back to the sequence  of  statements  of  this
  728. frame.
  729.  
  730.  
  731. Example:
  732.  
  733.     <<COMPARE>>
  734.        if A(I) < ELEMENT then
  735.           if LEFT(I) /= 0 then
  736.              I := LEFT(I);
  737.              goto COMPARE;
  738.           end if;
  739.           --  some statements
  740.        end if;
  741.  
  742.  
  743. References:  accept statement 9.5, block statement 5.6, case statement 5.4,
  744. compound  statement  5.1,  exception handler 11.2, frame 11.2, generic body
  745. 12.1, if statement 5.3, label 5.1, package body 7.1, program unit 6, select
  746. statement 9.7, sequence of statements 5.1, statement 5.1,  subprogram  body
  747. 6.3, task body 9.1, transfer of control 5.1
  748.